package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchTaskStudent;
import com.ruoyi.teach.service.ISchTaskStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务关联学生Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/task_student")
public class SchTaskStudentController extends BaseController
{
    @Autowired
    private ISchTaskStudentService schTaskStudentService;

    /**
     * 查询任务关联学生列表
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchTaskStudent schTaskStudent)
    {
        startPage();
        List<SchTaskStudent> list = schTaskStudentService.selectSchTaskStudentList(schTaskStudent);
        return getDataTable(list);
    }

    /**
     * 导出任务关联学生列表
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:export')")
    @Log(title = "任务关联学生", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchTaskStudent schTaskStudent)
    {
        List<SchTaskStudent> list = schTaskStudentService.selectSchTaskStudentList(schTaskStudent);
        ExcelUtil<SchTaskStudent> util = new ExcelUtil<SchTaskStudent>(SchTaskStudent.class);
        util.exportExcel(response, list, "任务关联学生数据");
    }

    /**
     * 获取任务关联学生详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:query')")
    @GetMapping(value = "/{tsId}")
    public AjaxResult getInfo(@PathVariable("tsId") Long tsId)
    {
        return AjaxResult.success(schTaskStudentService.selectSchTaskStudentByTsId(tsId));
    }

    /**
     * 新增任务关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:add')")
    @Log(title = "任务关联学生", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchTaskStudent schTaskStudent)
    {
        return toAjax(schTaskStudentService.insertSchTaskStudent(schTaskStudent));
    }

    /**
     * 修改任务关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:edit')")
    @Log(title = "任务关联学生", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchTaskStudent schTaskStudent)
    {
        return toAjax(schTaskStudentService.updateSchTaskStudent(schTaskStudent));
    }

    /**
     * 删除任务关联学生
     */
    @PreAuthorize("@ss.hasPermi('teach:task_student:remove')")
    @Log(title = "任务关联学生", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tsIds}")
    public AjaxResult remove(@PathVariable Long[] tsIds)
    {
        return toAjax(schTaskStudentService.deleteSchTaskStudentByTsIds(tsIds));
    }
}
